<template>
<view class="container">
		<view v-if="curTime" class="schedule_1">
			 <uni-calendar 
			    :insert="true"
			    :lunar="true" 
			    :start-date="'2018-01-01'"
			    :end-date="endTime"
				:date="selectDate"
			    @change="changeHandle"
			     />
				 <!-- curTime -->
		</view>
		<view class="schedule_2">
			<text>上课时间</text>
			<text>{{classTime.startDateTime || '暂无'}}</text>
		</view>
		<view class="schedule_3">
			<text>课程地点</text>
			<text>{{classRoom}}教室{{classRoom ? '' : '暂无'}}</text>
		</view>
		<view class="schedule_4">
			<text>课程节次</text>
			<text>课时{{classTime.node || '暂无'}}</text>
		</view>
</view>
</template>

<script>
	import { listClassTime } from '@/http/api.js'
	export default {
		data() {
			return {
				classId: '',
				year: '',
				month: '',
				date: '',
				classRoom: '',
				classTime: '',
				curTime: '',
				endTime: '',
				selectDate: '',
			};
			
		},
		methods: {
			initTime(){
				const time = new Date()
				const year = time.getFullYear()
				const month = time.getMonth() + 1
				const date = time.getDate()
				this.year = this.selectDate.slice(0,4)
				this.month = this.selectDate.slice(5,7)
				this.date = this.selectDate.slice(8,10)
				
				this.curTime = `${year}-${month}-${date}`
				this.endTime = `${year + 1}-${month}-${date}`
			},
			changeHandle(e){
				this.year = e.year
				this.month = e.month
				this.date = e.date
				this.getClassTime()
			},
			getClassTime(){
				this.classTime = ''
				this.classRoom = ''
				this.$request({
					url: listClassTime,
					data: {
						classId: this.classId,
						year: this.year,
						month: this.month,
						date: this.date
					}
				}).then( res => {
					res.some(item => {
						// const date = this.date < 10 ? `0${this.date}` : this.date.toString()
						const date = this.date.toString()
						if(item.classTime.date.slice(8,10) == date ){
							this.classTime = item.classTime 
							this.classRoom = item.classroom 
							return
						}
					})
				})
			}
		},
		onLoad(option){
			this.classId = option.classId || ''
			this.selectDate = option.date || ''
			this.initTime()
			this.getClassTime()
		}
		
	}
</script>

<style lang="scss">
	@import "./schedule.scss";
</style>
